package railRoad.web.slaves;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import railRoad.Passenger;
import railRoad.Ticket;
import railRoad.web.slaves.interfaces.ISlaveServlet;
import railRoad.worker.FactoryRW;

public class HistoryServlet implements ISlaveServlet {

	public void work(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		int pId = (Integer) req.getSession().getAttribute("passanger_id");

		Passenger passenger = new Passenger();

		passenger = FactoryRW.select(passenger, pId);

		if (passenger != null) {
			int size = passenger.size();

			ArrayList<Ticket> tickets = new ArrayList<Ticket>(size);

			for (int i = 0; i < size; i++) {
				tickets.add(passenger.getTicketAt(i));
			}

			req.getSession().setAttribute("tickets", tickets);
		}

		req.getSession().setAttribute("body", "/pages/order_list.jsp");

		resp.sendRedirect("/index.jsp");

	}// work

}// HistoryServlet
